<script setup lang="ts">
  import { ref } from 'vue';

  const data = {
    data: ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N'],
    sectionPadding: [0, 10, 0, 10] as Array<number>,
    scrollIntoView: "",
    scrolling: false
  }
  const activeIndex = ref(0)

</script>
<template>
  <view class="viewport">
    <view class="categories">
      <scroll-view class="primary" scroll-y>
        <view v-for="(item, index) in 10" :key="item" class="item" :class="{ active: index === activeIndex }"
              @tap="activeIndex = index">
          <text class="name"> 一级{{ item }} </text>
        </view>
      </scroll-view>
      <!-- 右侧：二级分类 -->
      <scroll-view enable-back-to-top class="secondary" scroll-y>

        <!-- 内容区域 -->
        <view class="panel" v-for="item in 10" :key="item.id">
          <view class="title">
            <text class="name">二级{{ item }}</text>
            <navigator class="more" hover-class="none">全部</navigator>
          </view>
          <view class="section">
            <navigator v-for="goods in 3" :key="goods" class="goods" hover-class="none"
                       >
              <image class="image" ></image>
              <view class="name ellipsis">商品{{ goods }}</view>
              <view class="price">
                <text class="symbol">¥</text>
                <text class="number">{{ goods }}</text>
              </view>
            </navigator>
          </view>
        </view>
      </scroll-view>
    </view>

  </view>

</template>
<style lang="scss">
  page {
    height: 100%;
    overflow: hidden;
  }

  .viewport {
    height: 100%;
    display: flex;
    flex-direction: column;
  }

  /* 分类 */
  .categories {
    flex: 1;
    min-height: 400rpx;
    display: flex;
  }

  /* 一级分类 */
  .primary {
    overflow: hidden;
    width: 180rpx;
    flex: none;
    background-color: #f6f6f6;

    .item {
      display: flex;
      justify-content: center;
      align-items: center;
      height: 96rpx;
      font-size: 26rpx;
      color: #595c63;
      position: relative;

      &::after {
        content: '';
        position: absolute;
        left: 42rpx;
        bottom: 0;
        width: 96rpx;
        border-top: 1rpx solid #e3e4e7;
      }
    }

    .active {
      background-color: #fff;

      &::before {
        content: '';
        position: absolute;
        left: 0;
        top: 0;
        width: 8rpx;
        height: 100%;
        background-color: #27ba9b;
      }
    }
  }

  .primary .item:last-child::after,
  .primary .active::after {
    display: none;
  }

  /* 二级分类 */
  .secondary {
    background-color: #fff;

    .carousel {
      height: 200rpx;
      margin: 0 30rpx 20rpx;
      border-radius: 4rpx;
      overflow: hidden;
    }

    .panel {
      margin: 0 30rpx 0rpx;
    }

    .title {
      height: 60rpx;
      line-height: 60rpx;
      color: #333;
      font-size: 28rpx;
      border-bottom: 1rpx solid #f7f7f8;

      .more {
        float: right;
        padding-left: 20rpx;
        font-size: 24rpx;
        color: #999;
      }
    }

    .more {
      &::after {
        font-family: 'erabbit' !important;
        content: '\e6c2';
      }
    }

    .section {
      width: 100%;
      display: flex;
      flex-wrap: wrap;
      padding: 20rpx 0;

      .goods {
        width: 150rpx;
        margin: 0rpx 20rpx 20rpx 0;

        &:nth-child(3n) {
          margin-right: 0;
        }

        .image {
          width: 150rpx;
          height: 150rpx;
        }

        .name {
          padding: 5rpx;
          font-size: 22rpx;
          color: #333;
        }

        .price {
          padding: 5rpx;
          font-size: 18rpx;
          color: #cf4444;
        }

        .number {
          font-size: 24rpx;
          margin-left: 2rpx;
        }
      }
    }
  }
</style>
